package com.superplayer.library.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.superplayer.library.Bean.VideoRightControlListBean;
import com.superplayer.library.R;

import java.util.List;

/**
 * 项目名称：SuperPlayer-master
 * 类描述：
 * 创建人：TianGenhu
 * 创建时间：2017/9/25 17:29
 * 修改人：TianGenhu
 * 修改时间：2017/9/25 17:29
 * 修改备注：
 */

public class SupterPlayerRightControlAdapter extends RecyclerView.Adapter<SupterPlayerRightControlAdapter.VideoViewHolder> {
    private final Context mContext;
    private List<VideoRightControlListBean> dataList;

    public SupterPlayerRightControlAdapter(Context context, List<VideoRightControlListBean> dataList) {
        this.mContext = context;
        this.dataList = dataList;
    }

    @Override
    public SupterPlayerRightControlAdapter.VideoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.view_super_player_right_item, null);
        VideoViewHolder holder = new VideoViewHolder(view);
        view.setTag(holder);
        return new VideoViewHolder(view);
    }

    @Override
    public void onBindViewHolder(SupterPlayerRightControlAdapter.VideoViewHolder holder, int position) {
        TextView playbillEpgTime = (TextView) holder.itemView.findViewById(R.id.playbill_epg_name);
        playbillEpgTime.setText(dataList.get(position).getName());
        holder.update(position);
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    public class VideoViewHolder extends RecyclerView.ViewHolder {
        public LinearLayout rlayPlayerControl;
        private RelativeLayout rlayPlayer;

        public VideoViewHolder(View itemView) {
            super(itemView);
            rlayPlayerControl = (LinearLayout) itemView.findViewById(R.id.linearLayout);
            rlayPlayer = (RelativeLayout) itemView.findViewById(R.id.app_video_right_box_item);
//            itemView.findViewById(R.id.super_video_right_touch_view).setOnTouchListener(new View.OnTouchListener() {
//                @Override
//                public boolean onTouch(View v, MotionEvent event) {
//                    Log.i("TGH", "onTouch: ddsadsd");
//                    if (playclick != null) {
//                        return playclick.onTouch(v, event);
//                    } else {
//                        return false;
//                    }
//                }
//            });
        }

        public void update(final int position) {
            //点击回调 播放视频
            rlayPlayerControl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.i("TGH", "点击出现问题了 吗");
                    if (playclick != null)
                        playclick.onPlayclick(position, rlayPlayerControl);
                }
            });
        }
    }

    private onPlayClick playclick;

    public void setPlayClick(onPlayClick playclick) {
        this.playclick = playclick;
    }

    public interface onPlayClick {
        void onPlayclick(int position, LinearLayout image);

//        boolean onTouch(View v, MotionEvent event);

    }

}